/**
 * Created by 李科风 on 2016-05-04.
 */

function openPostWindow(url) {
    var tempForm = document.createElement("form");
    tempForm.id = "tempForm1";
    tempForm.method = "post";
    tempForm.action = url;
    tempForm.target = "_blank";

    document.body.appendChild(tempForm);
    tempForm.submit();
    document.body.removeChild(tempForm);
}

define(["core", "tools"], function (core, tools) {
    var service = {};

    service.init = function () {
        scope = core.globalData("scope");

        $.get("/console/service/getDataService", function (data) {
            scope.services = data;
            scope.$apply();
        });
        scope.loginFusion = function () {
            $.ajax({
                url: "/console/service/loginFusion",
                success: function (data, status) {
                    openPostWindow(data);
                },
                error: function (obj, msg) {
                    tools.notifyMini({message: '跳转失败，请通知管理员修正'});
                }
            });
        }
        scope.jumpToService = function (id) {
            $.ajax({
                url: "/console/service/loginFusion",
                success: function (data, status) {
                    openPostWindow(data + "&serviceId=m_" + id);
                },
                error: function (obj, msg) {
                    tools.notifyMini({message: '跳转失败，请通知管理员修正'});
                }
            });
        }
    }

    return service;
})